﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.IO;

public partial class ApplicantApplyToVacancy : System.Web.UI.Page
{
    string UrlPath = "";
    string VacancyID = "";
    ApplicantMethord AM = new ApplicantMethord();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            UrlPath = Request.RawUrl.Substring(Request.RawUrl.LastIndexOf("/") + 1, Request.AppRelativeCurrentExecutionFilePath.Length - 2);
            if (Request.QueryString["ID"].ToString() != "")
            {
                UrlPath += "?ID=" + Request.QueryString["ID"].ToString();
            }
        }
        catch (Exception ex)
        {
        }
        try
        {
            Session["PageCurrent"] = UrlPath;
            lblError.Text = "";
            VacancyID = Request.QueryString["ID"].ToString();
            string User = Session["User"].ToString();
            txtUser.Text = "<a href='ChangeInformationApplicant.aspx'>" + User + "</a>";
            if ((Session["User"].ToString().Equals("")) || (Session["User"] == null))
            {
                Response.Redirect("LoginApplicant.aspx");
            }
            SqlDataReader dr = AM.ReturnVacancyOld(User);
            while (dr.Read())
            {
                lblVacancyApplying.Text = "<a href='VacancyDetails.aspx?ID="+dr.GetString(1)+"'>"+dr.GetString(0)+"</a>";
                int ints = dr.GetInt16(2);
                if (ints <3)
                {
                    lblError.Text = "Can not change when the scheduled interview";
                    btnChange.Enabled = false;
                }
            }
            AM.connClose();
            SqlDataReader dr1 = AM.ReturnVacancyNew(VacancyID);
            while (dr1.Read())
            {
                txtVacancyTitle.Text = "<a href='VacancyDetails.aspx?ID=" + dr1.GetString(0) + "'>" + dr1.GetString(1) + "</a>";
                txtVacancyID.Text = dr1.GetString(0);
            }
            AM.connClose();
            lblChangeApplicant.Text = "<a id=\"changApplicant\" href=\"ChangeInformationApplicant.aspx\"><marquee scrollamount=\"1\" behavior=\"alternate\" >Note: Check to make sure that personal information has been updated all</marquee></a>";
        }
        catch (Exception ex)
        {
            Response.Redirect("LoginApplicant.aspx");
        }
    }
    protected void btnChange_Click(object sender, EventArgs e)
    {
        bool Result = AM.ApplicantApplyToVancacy(Session["User"].ToString(), txtVacancyID.Text);
        if (Result)
        {
            Response.Write("<script type='text/javascript'>alert('Apply to vacancy successful');window.location='Home.aspx'</script>");
        }
        else
        {
            lblError.Text = "Error";
        }
    }
}